package com.example.teach.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.teach.entity.Course;
import com.example.teach.entity.Result;
import com.example.teach.mapper.CourseMapper;
import com.example.teach.service.CourseService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Resource
    private CourseMapper courseMapper;



    @Override
    public Course selectByName(String courseName) {
        return courseMapper.selectByName(courseName);
    }

    @Override
    public String addCourse(Integer majorId, Integer courseId) {
        if(majorId == null || courseId == null) {
            return "数据是空的";
        }
        if(courseMapper.selectNum(majorId,courseId) != 0){
            return "当前专业以有该课程";
        }
        courseMapper.save(majorId, courseId);
        return "课程添加成功";
    }

    @Override
    public Result selectByMajorId(Integer majorId) {
        return Result.success(courseMapper.list(majorId));
    }

    @Override
    public Result delete(Integer majorId, Integer courseId) {
        courseMapper.deleteOne(majorId,courseId);
        return Result.success();
    }

    @Override
    public void deleteById(Integer majorId) {
        courseMapper.remove(majorId);
    }
}
